package com.example.demo.utils;

import cn.hutool.http.HttpResponse;
import lombok.extern.log4j.Log4j2;
import org.elasticsearch.common.inject.internal.ErrorsException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletRequest;


@Log4j2
@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<Result> handleBusinessException(HttpServletRequest request, BusinessException ex) throws BusinessException {
        log.info("业务异常,code:{},msg:{}", ex.getCode(), ex.getMessage());
        Result result = new Result(ex.getCode(),ex.getMessage(),null);
        return new ResponseEntity(result, HttpStatus.OK);
    }

    // 其他异常处理...
}
